package cn.wolfcode.service.Impl;

import cn.wolfcode.domain.File;
import cn.wolfcode.mapper.FileMapper;
import cn.wolfcode.qo.PageResult;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IFileService;
import cn.wolfcode.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.Collections;
import java.util.List;

public class FileServiceImpl implements IFileService {

    @Override
    public PageResult<File> query(QueryObject qo) {
        //调用dao查询数据
        SqlSession session = MybatisUtil.openSession();
        FileMapper fileMapper=session.getMapper(FileMapper.class);
        int count = fileMapper.selectForCount(qo);
        //判断，查询回来的数据是否为0 如果为零说明没有数据，返回空集合
        if(count==0){//Collections.emptyList()空集合
            return new PageResult(qo.getCurrentPage(),qo.getPageSize(),count, Collections.emptyList());
        }
        //登录成功，跳转到首页，那么首先看到的是，第一页的3条数据
        List<File> products = fileMapper.selectForList(qo);

        //
        return new PageResult(qo.getCurrentPage(),qo.getPageSize(),count, products);
    }
}
